package com.xpgk.mvc.codeSet;

import java.util.List;

import com.jfinal.log.Log;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
import com.xpgk.mvc.right.Right;
import com.xpgk.plugin.ParamInitPlugin;
import com.xpgk.tools.ToolCache;

@SuppressWarnings("unused")
@Table(tableName = Code.table_name)
public class Code extends BaseModel<Code>{

	private static final long serialVersionUID = -6249187974185669048L;
	
	private static final Log log = Log.getLog(Code.class);

	public static final Code dao = new Code().dao();
	
	/**
	 * 表名称
	 */
	public static final String table_name = "sys_code";

	/**
	 * 字段描述：该条数据添加人员is  字段类型：character varying 长度：32
	 */
	public static final String column_createId = "createId";
	/**
	 * 字段描述：该条数据添加时间  字段类型：datetime 长度：0
	 */
	public static final String column_createDate = "createDate";
	/**
	 * 字段描述：该条数据更新人员id  字段类型：character varying 长度：100
	 */
	public static final String column_updateId = "updateId";
	/**
	 * 字段描述：该条数据更新时间  字段类型：datetime 长度：0
	 */
	public static final String column_updateDate = "updateDate";
	
	/**
	 * 字段描述：主键 字段类型：character varying 长度：32
	 */
	public static final String column_ids = "ids";
	
	/**
	 * 字段描述：名称 字段类型：character varying 长度：25
	 */
	public static final String column_name = "name";
	
	/**
	 * 字段描述：代码值 字段类型：character varying 长度：15
	 */
	public static final String column_code = "code";
	
	/**
	 * 字段描述：层级int 长度：2
	 */
	public static final String column_level = "level";

	/**
	 * 字段描述: 是否父节点 string 长度：5
	 */
	public static final String column_isparent = "isparent";
	
	/**
	 * 字段描述: 父节点ids string 长度：32
	 */
	public static final String column_parentids = "parentids";

	/**
	 * 字段描述: 序号 string 长度：11
	 */
	public static final String column_orderid = "orderid";

	/**
	 * 字段描述：图标 string 长度：50
	 */
	public static final String column_icon = "icon";
	
	/**
	 * 字段描述：是否默认值长度：1
	 */
	public static final String column_isDefault = "isDefault";
	
	/**
	 * 字段描述：状态 string 长度：1
	 */
	public static final String column_status = "status";
	
	
	
	
	
	/**
	 * sqlId : 描述：查询根节点
	 */
	public static final String sqlId_rootNode = "sys.code.rootNode";

	/**
	 * sqlId : 描述：根据上级节点id查询子部门信息
	 */
	public static final String sqlId_childNode = "sys.code.childNode";
	
	/**
	 * sqlId : 描述：根据上级节点id查询子节点数量
	 */
	public static final String sqlId_childCount = "sys.code.childCount";
	
	/**
	 * sqlId : 描述：分页Select
	 */
	public static final String sqlId_splitPageSelect = "sys.code.splitPageSelect";

	/**
	 * sqlId : 描述：分页from
	 */
	public static final String sqlId_splitPageFrom = "sys.code.splitPageFrom";
	
	/**
	 * sqlId : sys.right.paging 描述：查询所有参数
	 */
	public static final String sqlId_paging = "sys.code.paging";
	
	/**
	 * sqlId : 
	 * 描述：查询所有参数
	 */
	public static final String sqlId_all = "sys.code.all";
	
	/**
	 * sqlId : 
	 * 描述：查询子节点参数值
	 */
	public static final String sqlId_child = "sys.code.child";
	/**
	 * sqlId : 
	 * 描述：查询除疗程外的产品类型 ,查询除成交顾客外的顾客分类 
	 */
	public static final String sqlId_selProCode = "sys.code.selProCode";
	
	/**
	 * sqlId : 
	 * 描述：查询除疗程、药贴外的产品类型
	 */
	public static final String sqlId_selProCodeNOYT = "sys.code.selProCodeNOYT";
	
	/**
	 * sqlId : 
	 * 描述：通过code查询
	 */
	public static final String sqlId_byCode = "sys.code.byCode";
	
	
	/**
	 * 字段描述：消费类别 --购买
	 */
	public static final String xflb_gm = "xflbgm";
	/**
	 * 字段描述：消费类别 --转型
	 */
	public static final String xflb_zx = "xflbzx";
	/**
	 * 字段描述：消费类别 --收欠款
	 */
	public static final String xflbs_qk = "xflbsqk";
	/**
	 * 字段描述：单疗程使用单位---次
	 */
	public static final String dlc_units = "次";
	/**
	 * 字段描述：标准疗程使用单位---个
	 */
	public static final String bzlc_units = "斤";
	/**
	 * 字段描述：单疗程使用容量---个
	 */
	public static final String dlc_capacity= "20";
	/**
	 * 字段描述：单疗程使用剩余次数预警（少于此个数预警）---个
	 */
	public static final String dlc_warring= "3";
	/**
	 * 字段描述：一疗程使用容量---个
	 */
	public static final String ylc_capacity= "10";
	/**
	 * 字段描述：保存图片的地址路径
	 */
	//public static final String savePicture_path= "F:/javaPro/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/shouba2.0/uploadzp/";
	public static final String savePicture_path= "/usr/local/apache-tomcat-8.0.39/webapps/shouba2.0/uploadzp/";
	
	
	
	/**
	 * 字段描述：一疗程带售后ids
	 */
	public static final String ylcdsh_ids = "27aeb2d41d044394b9b58f6814baa4fa";
	/**
	 * 字段描述：标准疗程ids
	 */
	public static final String bzlc_ids = "0896ce4d4970455d9184e6dd1ced6a0e";
	/**
	 * 字段描述：单疗程ids
	 */
	public static final String dlc_ids = "4777c2c215b6408ab13c1eac4190ce46";
	/**
	 * 字段描述：瘦身ids
	 */
	public static final String ss_ids = "a07f80b6d9064a2e8357f0f87d21a115";
	
	/**
	 * 字段描述：进店方式-转介绍ids
	 */
	public static final String zjs_ids = "7baa3f3fc25d4caa924f963584e5af21";
	
	/**
	 * 字段描述：进店方式-宣传ids
	 */
	public static final String xc_ids = "214e103ff60040468395995891cd9ee7";
	
	
	
	/**
	 * 字段描述：产品类型ids
	 */
	public static final String proType_ids = "d0741f09bd9a4a7bb4b8b46872a8009e";
	/**
	 * 字段描述：减重目标模式ids
	 */
	public static final String delWeiMoshi_ids = "0ea6765b42204ab3866458d2aefa99fd";
	/**
	 * 字段描述：疗程ids
	 */
	public static final String lc_ids = "455018290a8f4afbbaf29c61904d6406";
	/**
	 * 字段描述：成交顾客code表ids
	 */
	public static final String cjCus_ids = "607f10b77f4d4b908104e990f366a334";
	/**
	 * 字段描述：产品用途为服务的ids
	 */
	public static final String cpytFw_ids = "f251248c324f436c8b8ff21a4a06bbc1";
	/**
	 * 字段描述：药贴ids
	 */
	public static final String proYt_ids = "c3df895ee3b24d1193cb8156edc665b7";
	
	/**
	 * 字段描述：药贴类型ids
	 */
	public static final String proYtLX_ids = "5e2501ca2a024b43b9b5aa47f041452f";
	
	/**
	 * 进店方式ids
	 */
	public static final String jdfs_ids ="ce752c5ca77e46af97bb70c5c202553c";
	
	public static final String code_jdfs ="code_jdfs";
	/**
	 * 顾客分类ids
	 */
	public static final String gkfl_ids ="a36995afed914ba291b573c6acc2fede";
	
	public static final String code_gkfl ="code_gkfl";
	/**
	 * 未成交原因ids
	 */
	public static final String wcjyy_ids ="5091e96200344b13bbcd58abd980c5a4";
	
	public static final String code_wcjyy ="code_wcjyy";
	
	
	/**
	 * 量尺寸时间设置
	 */
	public static final String lccsz_ids ="fa0a95443d6a4310b53c461d51498bf0";
	
	public static final String code_lccsz ="code_lccsz";
	
	
	
	
	/**疗程
	 * 
	 */
	public static final String code_lc ="code_lc";
	
	/**
	 * 产品类型ids
	 */
	public static final String cplx_ids ="d0741f09bd9a4a7bb4b8b46872a8009e";
	
	public static final String code_cplx ="code_cplx";
	
	/**
	 * 产品用途
	 */
	public static final String cpyt_ids = "eb174c16c574407a87df9581b049333e";
	
	public static final String code_cpyt = "code_cpyt";
	
	/**
	 * 收款方式ids
	 */
	public static final String skfs_ids ="7059a3542c884a7d8e16b102a1fe6d87";
	
	public static final String code_skfs ="code_skfs";
	
	/**
	 * 行政区划ids
	 */
	public static final String xzqh_ids ="d1870e1162b040e2b03bd715a1aaa046";
	
	public static final String code_xzqh ="code_xzqh";
	
	/**
	 * 民族ids
	 */
	public static final String nation_ids ="f0c9efff21b744d8b199fb55f511cd60";
	
	public static final String code_nation ="code_nation";
	
	/**
	 * 婚姻状况ids
	 */
	public static final String marry_ids ="57e2b1a189a041afad54659285d14683";
	
	public static final String code_marry ="code_marry";
	
	
	/**
	 * 离职原因ids
	 */
	public static final String outReason_ids ="f4e5b040dbdc40e9a26f9ce2701add47";
	
	public static final String code_outReason ="code_outReason";
	
	
	/**
	 * 活动方式ids
	 */
	public static final String activityWay_ids ="1b973bb4e6bc48518ad293954b5028de";
	
	public static final String code_activityWay ="code_activityWay";
	
	/**
	 * 政治面貌ids
	 */
	public static final String zzmm_ids ="d923e65f7af1466fba0dd6777aa43972";
	
	public static final String code_zzmm ="code_zzmm";
	
	/**
	 * 学历ids
	 */
	public static final String xl_ids ="b1e3f76a31af4bbcbb1d114773726ef2";
	
	public static final String code_xl ="code_xl";
	
	/**
	 * 健康状况ids
	 */
	public static final String jkzk_ids ="feac1c0e06e04a8e9645cf480675b3af";
	
	public static final String code_jkzk ="code_jkzk";
	
	/**
	 * 顾客反映ids
	 */
	public static final String gkfy_ids ="d705a2368782408fbf57919dec6348ff";
	
	public static final String code_gkfy ="code_gkfy";
	
	/**
	 * 服务部位ids
	 */
	public static final String fwbw_ids = "cb8db117b3f44b78bfdb9ae8f288810b";
	/**
	 * 测量部位ids
	 */
	public static final String clbw_ids = "02287f74bb274419b0cbf8b7d6544867";
	
	/**
	 * 减重目标模式ids
	 */
	public static final String mbms_ids = "0ea6765b42204ab3866458d2aefa99fd";
	
	public static final String code_mbms = "code_mbms";
	/**
	 * 出库原因ids
	 */
	public static final String ckyy_ids = "191fd574add742a3b0c7aabd4bcd1901";
	
	public static final String code_ckyy = "code_ckyy";
	/**
	 * 费用支出ids
	 */
	public static final String fyzc_ids = "a57e349c3fb1457792637bf0fe729a7f";
	
	public static final String code_fyzc = "code_fyzc";
	/**
	 * 退款原因ids
	 */
	public static final String tkyy_ids = "1483d23c38904e508fce91211b96f394";
	
	public static final String code_tkyy = "code_tkyy";
	
	/**
	 * 计算机水平ids
	 */
	public static final String jsjsp_ids = "4a57578b212b49d5b5fcfe37da6ae46c";
	
	public static final String code_jsjsp = "code_jsjsp";
	
	/**
	 * 计算机水平ids
	 */
	public static final String xzjb_ids = "c217c4928dda4151b13155c92e12ef95";
	
	public static final String code_xzjb = "code_xzjb";
	/**
	 * 预警ids
	 */
	public static final String yjsz_ids = "4dd098f3ce094aba8f4d8425fee4f5fb";
	
	public static final String code_yjsz = "code_yjsz";
	
	
	/**
	 * 转店原因ids
	 */
	public static final String zdyy_ids = "662c2f4f944842cd994bcbf7fe36c4ca";
	
	public static final String code_zdyy = "code_zdyy";
	/**
	 * 请假类别ids
	 */
	public static final String qjlb_ids="c3f9982e2b2941109a094a872aa7e90b";
	
	public static final String code_qjlb="code_qjlb";
	
	public static String getCode(String key) {
		String result = null;
		if(code_jdfs.equals(key)){
			result = jdfs_ids;
		}
		if(code_lc.equals(key)){
			result = lc_ids;
		}
		if(code_gkfl.equals(key)){
			result = gkfl_ids;
		}
		if(code_cplx.equals(key)){
			result = cplx_ids;
		}
		if(code_cpyt.equals(key)){
			result = cpyt_ids;
		}
		if(code_xzqh.equals(key)){
			result = xzqh_ids;
		}
		if(code_skfs.equals(key)){
			result = skfs_ids;
		}
		if(code_mbms.equals(key)){
			result = mbms_ids;
		}
		if(code_gkfy.equals(key)){
			result = gkfy_ids;
		}
		if(code_ckyy.equals(key)){
			result = ckyy_ids;
		}
		if(code_fyzc.equals(key)){
			result = fyzc_ids;
		}
		if(code_tkyy.equals(key)){
			result = tkyy_ids;
		}
		if(code_nation.equals(key)){
			result = nation_ids;
		}
		if(code_activityWay.equals(key)){
			result = activityWay_ids;
		}
		if(code_xl.equals(key)){
			result = xl_ids;
		}
		if(code_zzmm.equals(key)){
			result = zzmm_ids;
		}
		if(code_zdyy.equals(key)){
			result = zdyy_ids;
		}
		if(code_outReason.equals(key)){
			result = outReason_ids;
		}
		if(code_wcjyy.equals(key)){
			result = wcjyy_ids;
		}
		if(code_marry.equals(key)){
			result = marry_ids;
		}
		if(code_jkzk.equals(key)){
			result = jkzk_ids;
		}
		if(code_jsjsp.equals(key)){
			result = jsjsp_ids;
		}
		if(code_xzjb.equals(key)){
			result = xzjb_ids;
		}
		if(code_qjlb.equals(key)){
			result = qjlb_ids;
		}
		if(code_yjsz.equals(key)){
			result = yjsz_ids;
		}
		return result;
	}
	
	/**
	 * 查询子节点参数
	 * @return
	 */
	public List<Code> getChild(){
		String sql = getSqlMy(sqlId_child);
		return dao.find(sql, getPKValue());
	}
	
	/**
	 * 添加或者更新缓存
	 */
	public static void cacheAdd(String ids) {
		
		Code code = Code.dao.findById(ids);
		if(null != code){
			String dmz = code.getStr(Code.column_code);
			List<Code> codeList = code.getChild();
			ToolCache.set(ParamInitPlugin.cacheStart_code + code.getPKValue(), code);
			ToolCache.set(ParamInitPlugin.cacheStart_code_child + code.getPKValue(), codeList);
			if(null != dmz){
				ToolCache.set(ParamInitPlugin.cacheStart_code + dmz, code);
				ToolCache.set(ParamInitPlugin.cacheStart_code_child + dmz, codeList);
			}
			
			String codeIds = code.getStr(Code.column_parentids);
			if(null != codeIds){
				Code parent = Code.dao.findById(codeIds);
				if(null != parent){
					String pdmz = parent.getStr(Code.column_code);
					List<Code> parentList = parent.getChild();
					ToolCache.set(ParamInitPlugin.cacheStart_code_child + parent.getPKValue(), parentList);
					if(null != pdmz){
						ToolCache.set(ParamInitPlugin.cacheStart_code_child + pdmz, parentList);
					}
				}
			}
		}
	}
	
	/**
	 * 删除缓存
	 * 
	 * @param ids
	 */
	public static void cacheRemove(String ids, String parentIds) {
		Code code = cacheGet(ids);
		if(null != code){
			String dmz = code.getStr(Code.column_code);
			ToolCache.remove(ParamInitPlugin.cacheStart_code + ids);
			ToolCache.remove(ParamInitPlugin.cacheStart_code_child + ids);
			if(null != dmz){
				ToolCache.remove(ParamInitPlugin.cacheStart_code + dmz);
				ToolCache.remove(ParamInitPlugin.cacheStart_code_child + dmz);
			}
		}

		if(null != parentIds){
			Code parent = Code.dao.findById(parentIds);
			if(null != parent){
				String pdmz = parent.getStr(Code.column_code);
				List<Code> parentList = parent.getChild();
				ToolCache.set(ParamInitPlugin.cacheStart_code_child + parent.getPKValue(), parentList);
				if(null != pdmz){
					ToolCache.set(ParamInitPlugin.cacheStart_code_child + pdmz, parentList);
				}
			}
		}
	}
	
	/**
	 * 获取缓存
	 * 
	 * @param key
	 * @return
	 */
	public static Code cacheGet(String key) {
		Code code = ToolCache.get(ParamInitPlugin.cacheStart_code + key);
		if(code == null){
			code = Code.dao.findById(key);
			cacheAdd(code.getPKValue());
		}
		return code;
	}
	
	/**
	 * 获取缓存
	 * @param numbers
	 * @return
	 */
	public static List<Code> cacheGetChild(String key){
		List<Code> codeList = ToolCache.get(ParamInitPlugin.cacheStart_code_child + key);
		if(codeList == null){
			Code pCode = cacheGet(key);
			String sql = getSqlMy(sqlId_child);
			codeList = Code.dao.find(sql, pCode.getPKValue());
			cacheAdd(key);
		}
		return codeList;
	}
	
	/**
	 * 获取缓存
	 * 
	 * @param dmz
	 * @return
	 */
	public static Code cacheGetByCode(String dmz) {
		Code code = ToolCache.get(ParamInitPlugin.cacheStart_code + dmz);
		if(code == null){
			String sql = getSqlMy(sqlId_byCode);
			code = Code.dao.findFirst(sql, dmz);
			if(null != code){
				cacheAdd(code.getPKValue());
			}
		}
		return code;
	}
	
	/**
	 * 获取缓存
	 * @param dmz
	 * @return
	 */
	public static List<Code> cacheGetChildByCode(String dmz){
		List<Code> codeList = ToolCache.get(ParamInitPlugin.cacheStart_code_child + dmz);
		if(codeList == null){
			Code pCode = cacheGetByCode(dmz);
			String sql = getSqlMy(sqlId_child);
			codeList = Code.dao.find(sql, pCode.getPKValue());
			cacheAdd(pCode.getPKValue());
		}
		return codeList;
	}


}
